import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/auth/auth_button.dart';

class ATHScanLoginBody extends StatefulWidget {
  @override
  _ATHScanLoginBodyState createState() => _ATHScanLoginBodyState();
}

class _ATHScanLoginBodyState extends State<ATHScanLoginBody> {
  @override
  void initState() {
    super.initState();

//    Map<String, dynamic> params = HashMap();
//    params["m_ticket"] = "705cc812-6ad5-4ea6-8ad4-b2ff94323bfb";
//    RequestManager.instance
//        .post("api/v1/qrcode/sanlogin", params: params)
//        .then((value) => print(value.toJson()));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: kCommonMarin,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              CloseButton(),
              IconButton(icon: Icon(Icons.error), onPressed: () {})
            ],
          ),
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SvgPicture.asset("assets/icons/icon_scan_login_compute.svg",
                  width: kSize360),
              Text(
                "Moose 网页版登录确认",
                style: TextStyle(
                    fontSize: kFontSize38, fontWeight: FontWeight.bold),
              ),
              Divider(
                indent: kSize56,
                endIndent: kSize56,
              ),
              Container(
                margin: EdgeInsets.symmetric(horizontal: kSize120),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    ATHScanLoginIcon(
                      iconPath: "icon_location",
                      text: "北京市",
                    ),
                    ATHScanLoginIcon(
                      iconPath: "icon_compute",
                      text: "Mac OS",
                    ),
                    ATHScanLoginIcon(
                        iconPath: "icon_brower", text: "Chromefdsafds"),
                  ],
                ),
              )
            ],
          )),
          Container(
            height: kSize300,
            child: Column(
              children: [
                ATHAuthButton(
                  text: "登录",
                  press: () {},
                ),
                ATHAuthButton(
                  text: "取消",
                  color: Colors.white,
                  textColor: kColor99,
                  press: () {
                    if (Navigator.canPop(context)) {
                      Navigator.pop(context);
                    }
                  },
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}

class ATHScanLoginIcon extends StatelessWidget {
  final String iconPath;

  final String text;

  const ATHScanLoginIcon(
      {Key key, this.iconPath = "icon_location", this.text = ""})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        SvgPicture.asset(
          "assets/icons/$iconPath.svg",
          width: kSize42,
        ),
        Container(
          width: kSize100,
          margin: EdgeInsets.only(left: kSize8),
          child: Text(
            text,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
        )
      ],
    );
  }
}
